import urllib

import requests

def askUrl(url):
    head = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36"
    }
    request = urllib.request.Request(url, headers=head)
    html = ""
    try:
        response = urllib.request.urlopen(request, timeout=60)
        html = response.read().decode('utf-8')
        response.close()
    except urllib.error.URLError as e:
        print(e)
    return html

query = input("输入一个你喜欢的明星")
url = f'https://www.sogo.com/web?query={query}'
headers = {
    "UserAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
                 "Chrome/94.0.4606.61 Safari/537.36 "
}
resp = askUrl(url)
print(resp)

# print("resp.request = ", resp.request)
# print("resp.text = ", resp.text)
# print("resp.json = ", resp.json)
# print("resp.cookies = ", resp.cookies)
# print("resp.encoding = ", resp.encoding)


